<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: mslaria $ ($Date: 2007/07/11 13:08:20 $)
// $RCSfile: staff_ajax.php,v $ : $Revision: 1.6 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}


header("Content-type: text/html; charset=".$_SWIFT["language"]["charset"]);

/**
* ###############################################
* FETCH ARTICLE
* ###############################################
*/
if ($_GET["type"] == "fetcharticle")
{
	require_once ("./modules/knowledgebase/functions_knowledgebase.php");
	require_once ("./includes/functions_html.php");
	require_once ("./includes/functions_users.php");
	require_once ("./includes/functions_jscache.php");
	require_once ("./includes/data_mimelist.php");
	$template->loadLanguageSection("knowledgebase");

	if (!empty($_GET["kbarticleid"]))
	{
		$_kb = $dbCore->queryFetch("SELECT *, kbarticles.dateline AS articledateline FROM `". TABLE_PREFIX ."kbarticles` AS kbarticles LEFT JOIN `". TABLE_PREFIX ."kbarticledata` AS kbarticledata ON (kbarticles.kbarticleid = kbarticledata.kbarticleid) WHERE kbarticles.kbarticleid = '". intval($_GET["kbarticleid"]) ."'");
		echo strip_tags(str_replace("<br />", "\n", str_replace("<BR />", "\n", $_kb["contents"])));
	}



/**
* ###############################################
* IRS
* ###############################################
*/
} else if ($_GET["type"] == "irs") {
	if (empty($_GET["query"]) || !$module->isRegistered(MODULE_TICKETS) || $_SWIFT["settings"]["t_scanirs"] != 1)
	{
		exit;
	}

	require_once ("./modules/knowledgebase/functions_irs.php");

	$_irsresults = _runIRS($_GET["query"], true);

	if (_is_array($_irsresults))
	{
		$_irscount = 0;
		foreach ($_irsresults as $irskey=>$irsval)
		{
			$_irscount++;

			if ($_irscount == 7)
			{
				break;
			}

			$_subject = str_replace(";","", $irsval["subject"]);
			echo iif(strlen($_subject)>40, substr($_subject,0,40)."..", $_subject).";".$irsval["kbarticleid"].";".$irsval["relevance"]."\n";
		}
	}
}

?>